fix: remove single-quoted Python literal from claude stream processor#153
Open
alilxxey wants to merge 1 commit intoasklokesh:mainfrom
Open
fix: remove single-quoted Python literal from claude stream processor#153alilxxey wants to merge 1 commit intoasklokesh:mainfrom
alilxxey wants to merge 1 commit intoasklokesh:mainfrom
Conversation
The claude provider pipes stream-json output through `python3 -u -c '...'`
to track tool usage and update the dashboard orchestrator. The Grep branch
used `f"pattern: {tool_input.get('pattern', '')}"`, embedding four single
quotes inside what is already a bash single-quoted string.
Bash toggles its SQ state on every literal `'`, so the four quotes fall
back to SQ-in state (even number of toggles), hiding the problem from
bash syntax checks. But each pair also strips its contents out of the
SQ, so `'pattern'` becomes a bare word and Python receives
`tool_input.get(pattern, )` -- a valid-but-wrong expression that raises
`NameError: name "pattern" is not defined` on every Grep call.
The exception aborts the inner `for item in content` loop before
`update_orchestrator_task` runs, so Grep invocations were silently
missing from `.loki/state/agents.json` and the dashboard tool counter.
Claude sessions continued, but every Grep also printed a spurious
`[Parse error: name 'pattern' is not defined]` to stderr.
Fix: use double quotes and string concatenation, which stays safe
inside bash SQ. Add BUG-RUN-004 regression assertions in
tests/test-bugfix-audit.sh to prevent reintroducing the pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The claude provider pipes stream-json output through
python3 -u -c '...'to track tool usage and update the dashboard orchestrator. The Grep branch usedf"pattern: {tool_input.get('pattern', '')}", embedding four single quotes inside what is already a bash single-quoted string.Bash toggles its SQ state on every literal
', so the four quotes fall back to SQ-in state (even number of toggles), hiding the problem from bash syntax checks. But each pair also strips its contents out of the SQ, so'pattern'becomes a bare word and Python receivestool_input.get(pattern, )-- a valid-but-wrong expression that raisesNameError: name "pattern" is not definedon every Grep call.The exception aborts the inner
for item in contentloop beforeupdate_orchestrator_taskruns, so Grep invocations were silently missing from.loki/state/agents.jsonand the dashboard tool counter. Claude sessions continued, but every Grep also printed a spurious[Parse error: name 'pattern' is not defined]to stderr.Fix: use double quotes and string concatenation, which stays safe inside bash SQ. Add BUG-RUN-004 regression assertions in tests/test-bugfix-audit.sh to prevent reintroducing the pattern.
Description
The claude provider pipes stream-json output through
python3 -u -c '...'to track tool usage in the dashboard orchestrator. The Grep branch at
autonomy/run.sh:9743used:embedding four single quotes inside what is already a bash single-quoted
heredoc. Bash cannot contain a literal
'inside'...'— every'toggles SQ state. Four toggles leave the shell back in SQ mode (which is
why
bash -nsees no syntax error), but each pair strips its contentsout of the SQ. Python receives:
a valid-but-wrong expression —
patternis now a bare identifierinstead of a string literal — and crashes with:
The exception is caught at
run.sh:9818and printed to stderr as[Parse error: name 'pattern' is not defined], which users seerepeatedly in logs — once per Grep tool call. Because the exception
exits the inner
for item in contentloop beforeupdate_orchestrator_task(tool, tool_desc)runs, Grep calls are alsosilently missing from
.loki/state/agents.jsonand the dashboardtool counter undercounts.
Reproduction
Isolated repro confirming the exact NameError: